package com.wxxymaker.edu.controller;

import com.blade.ioc.annotation.Inject;
import com.blade.mvc.annotation.Param;
import com.blade.mvc.annotation.Path;
import com.blade.mvc.annotation.PathParam;
import com.blade.mvc.annotation.PostRoute;
import com.blade.mvc.ui.RestResponse;
import com.wxxymaker.edu.model.entity.Practice;
import com.wxxymaker.edu.service.PracticeService;

/**
 * @AUTHOR soft
 * @DATE 2018/10/13 22:50
 * @DESCRIBE
 */
@Path(value = "/course/set/practice", restful = true)
public class PracticeHandler {

    @Inject
    private PracticeService practiceService;

    @PostRoute("/:kid/add")
    public RestResponse add(@PathParam Integer kid,
                            @Param Practice practice) {
        practice.setCourseId(kid);
        Practice practice1 = practiceService.add(practice);
        if (practice1 != null) {
            return RestResponse.ok(practice1);
        }
        return RestResponse.fail();
    }

    @PostRoute("/:kid/change")
    public RestResponse change(Practice practice) {
        Integer pid = practice.getId();
        if (practiceService.change(practice)) {
            practice.setId(pid);
            return RestResponse.ok(practice);
        }
        return RestResponse.fail();
    }

    @PostRoute("/:kid/delete/:id")
    public RestResponse delete_(@PathParam Integer id) {
        Practice delete = practiceService.delete(id);
        if (delete != null) {
            return RestResponse.ok(delete);
        }
        return RestResponse.fail();
    }
}
